var pro_load_page = 2,pro_load_flag = true;
window.sessionStorage.setItem('profit_list_type',0);
	footer.init();
	header.init('收益明细');	
var detailList = {
	init : function(type){
		app.ajax(
		'/Member/Shop/income_statement',
		{
			page :1,
			type :type
		},function(res){
			if(res.code == 200){
				app.tpl($('.detail-list'),'tpl-detail-list',res);
				type = parseInt(type);
				$('.list-nav .mui-col-xs-4:nth-child('+(type+1)+')').addClass('font-active');
				$('.list-nav .mui-col-xs-4:nth-child('+(type+1)+')').siblings().addClass('font-normal');
			}else{
				layer.msg('网络繁忙，请稍候再试');
			}
		});
	},
	loadMore :function(data){
		var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;" class="no-more">努力加载中~<div>';
   		$('.Dlist').append(listLoadingEmpty);
		pro_load_flag = false;
		app.ajax(
			'/Member/Shop/income_statement',
			data,
			function(res){
				$('.Dlist .no-more').remove();
				if(res.code == 200){
					var list = res.list,
					html='';
					for(var i=0;i<list.length;i++){
						var price = list[i].price <0 ? list[i].price : '+'+list[i].price;
						var time = list[i].create_time;
						var data1 = time.substr(0,10);
						data1 = data1.split('-');
						time = data1[1]+'/'+data1[2];
						html+="<section class='bT pT9 '><div class='mui-row pT9 pB9' data-menId = '"+list[i].member_id+"' data-id ='"+list[i].id+"'>"
							+"<div class='mui-col-xs-4 fS13 tC lH25'>"+time+"</div><div class='mui-col-xs-8 fS13 lH25 pL10'><div>"
							+price+"</div><p>"+list[i].description+"</p></div></div></section>";
					}
					$('.Dlist').append(html);
						pro_load_page++;
						pro_load_flag = true;
					
					//page++;
				}else{						
						var listLoadingEmpty = '<div style="height:3rem;line-height:3rem;text-align:center;font-size:1.2rem;">没有更多数据了~<div>';
						$('.Dlist').append(listLoadingEmpty);
						pro_load_flag = false;
				}
			});	
	}
};
detailList.init(0);

	window.onload = function(){
		$('.list-nav .mui-col-xs-4').addClass('font-normal');
		$('body').on('click','.list-nav .mui-col-xs-4',function(){
			var type = $(this).attr('data-type');
			window.sessionStorage.setItem('profit_list_type',type);
			detailList.init(type);
		});
		
		$(window).scroll(function(){
		// 当滚动到距底部以上200像素
		var offset = $(".Dlist").offset(),
		dataType = 0,
		data = {};
		var documentHeight = offset.top + $(".Dlist").height();
		if (documentHeight - $(this).scrollTop() - $(this).height()<100){
				 dataType=window.sessionStorage.getItem('profit_list_type');
				data = {
					page :pro_load_page,
					type : dataType
				};
			pro_load_flag && detailList.loadMore(data);
		}
	});
		
	}
